package com.deft.design.abstracts.factory;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * @author zdl
 * @description
 * @date 2022-04-18
 **/
public class DbProxy {

    public static <T> T getProxy(Class<T> interfaceClass, IDatabaseAdapter databaseAdapter) {
        InvocationHandler handler = new DbInvocationHandler(databaseAdapter);
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        Class<?>[] classes = interfaceClass.getInterfaces();
        return (T) Proxy.newProxyInstance(classLoader, new Class[]{classes[0]}, handler);
    }
}
